home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / simula / books / books.lha / kirkerud / filetools.sim < prev    next >
Text File  |  1993-08-16  |  2KB  |  60 lines

  1. class filetools;
  2.   begin
  3.   
  4.     procedure text_to_file(f, t); ref(outfile) f; text t;
  5.       begin f.outtext(t); f.outchar(separator) end;
  6.  
  7.     procedure int_to_file(f, i); ref(outfile) f; integer i;
  8.       begin f.outint(i, 0); f.outchar(separator) end;
  9.  
  10.     procedure real_to_file(f, r); ref(outfile) f; real r;
  11.       begin f.outreal(r, 9, 0); f.outchar(separator) end;
  12.  
  13.     text procedure text_from_file(f); ref(infile) f;
  14.       if f.lastitem 
  15.         then text_from_file :- notext
  16.         else begin character c; text tt, ta;
  17.           c := f.inchar; tt :- blanks(1);
  18.           while c ne separator do
  19.             begin
  20.               if not tt.more then
  21.                 begin 
  22.                   ta :- tt; tt :- blanks(2*tt.length); 
  23.                   tt := ta; tt.setpos(ta.length + 1);
  24.                 end;
  25.               tt.putchar(c);
  26.               if not f.more then f.inimage;
  27.               c := if f.endfile then separator else f.inchar;
  28.             end; 
  29.           text_from_file :- tt.strip;
  30.         end;
  31.  
  32.     integer procedure int_from_file(f); ref(infile) f;
  33.       begin text tt;
  34.         tt :- text_from_file(f);
  35.         if tt == notext then int_from_file := 0
  36.         else begin character c; 
  37.           tt.setpos(1); c := tt.getchar; 
  38.           if not (digit(c) or c = '-' or c = '+') 
  39.             then int_from_file := 0
  40.             else begin tt.setpos(1); int_from_file := tt.getint end;
  41.         end;
  42.       end;
  43.  
  44.     real procedure real_from_file(f); ref(infile) f;
  45.       begin text tt;
  46.         tt :- text_from_file(f);
  47.         if tt == notext then real_from_file := 0
  48.         else begin character c; 
  49.           tt.setpos(1); c := tt.getchar; 
  50.           if not (digit(c) or c = '-' or c = '+') 
  51.             then real_from_file := 0
  52.             else begin tt.setpos(1); real_from_file := tt.getreal end;
  53.         end;
  54.       end;
  55.  
  56.     character separator;
  57.     
  58.     separator := '"';
  59.     
  60.   end filetools;